import instance from '@/utils/myhttp.js'

// 获取用户信息
function apiUserData () {
  return instance({
    url: '/app/v1_0/user',
    method: 'get'
  })
}

// 获取用户生日、性别
function apiProfile () {
  return instance({
    url: '/app/v1_0/user/profile',
    method: 'get'
  })
}

// 保存用户信息 /app/v1_0/user/profile
function apiUpdateProfile ({ name, gender, birthday, intro }) {
  return instance({
    url: '/app/v1_0/user/profile',
    method: 'PATCH',
    data: {
      name: name,
      gender: gender,
      birthday: birthday,
      intro: intro
    }
  })
}

// 头像上传
function apiPhoto (photo) {
  // axios无法进行文件上传需要借助formData
  var fd = new FormData()
  fd.append('photo', photo)
  return instance({
    url: '/app/v1_0/user/photo',
    method: 'PATCH',
    data: fd
  })
}

export { apiUserData, apiProfile, apiUpdateProfile, apiPhoto }
